home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 4.iso
/
src
/
haeberli
/
tools
/
resglue.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-08-01
|
3KB
|
108 lines
/*
* Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
* All Rights Reserved.
*
* This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
* the contents of this file may not be disclosed to third parties, copied or
* duplicated in any form, in whole or in part, without the prior written
* permission of Silicon Graphics, Inc.
*
* RESTRICTED RIGHTS LEGEND:
* Use, duplication or disclosure by the Government is subject to restrictions
* as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
* and Computer Software clause at DFARS 252.227-7013, and/or in similar or
* successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
* rights reserved under the Copyright Laws of the United States.
*/
#include "stdio.h"
#define BACKMAGIC (('P'<<24)+('A'<<16)+('U'<<8)+('L'<<8))
#define MAXRES (100)
char nametab[MAXRES][32];
int offsettab[MAXRES];
int lengthtab[MAXRES];
main(argc,argv)
int argc;
char **argv;
{
int i, n, pos;
FILE *outf, *inf;
long magic;
char cmd[256];
if(argc<4) {
fprintf(stderr,"usage: resglue progin progout files . . . . \n");
exit(1);
}
outf = fopen("/usr/tmp/XXXX.resglue","w");
if(!outf) {
fprintf(stderr,"resglue: can't open output file for writing\n");
exit(1);
}
inf = fopen(argv[1],"r");
if(!inf) {
fprintf(stderr,"resglue: can't open input file %s for reading\n",argv[1]);
exit(1);
}
pos = fcopy(inf,outf);
fclose(inf);
n = 0;
for(i=3; i<argc; i++) {
offsettab[n] = pos;
strcpy(nametab[n],argv[i]);
inf = fopen(argv[i],"r");
if(!inf) {
fprintf(stderr,"resglue: can't open input file %s for append\n",argv[i]);
exit(1);
}
lengthtab[n] = fcopy(inf,outf);
pos += lengthtab[n];
close(inf);
n++;
if(n == MAXRES) {
fprintf(stderr,"resglue: max resource files is %d for now\n",MAXRES);
exit(1);
}
}
for(i=0; i<n; i++) {
fwrite(nametab[i],32,1,outf);
fwrite(&offsettab[i],sizeof(long),1,outf);
fwrite(&lengthtab[i],sizeof(long),1,outf);
}
fwrite(&n,sizeof(long),1,outf);
magic = BACKMAGIC;
fwrite(&magic,sizeof(long),1,outf);
fwrite(&magic,sizeof(long),1,outf);
fwrite(&magic,sizeof(long),1,outf);
if(ferror(outf)) {
fprintf(stderr,"resglue: error writing file\n");
exit(1);
}
fclose(outf);
sprintf(cmd,"mv /usr/tmp/XXXX.resglue %s",argv[2]);
system(cmd);
sprintf(cmd,"chmod +x %s",argv[2]);
system(cmd);
}
int fcopy(inf,outf)
FILE *inf, *outf;
{
char tmpbuf[10240];
int nbytes, totbytes;
totbytes = 0;
while(1) {
nbytes = fread(tmpbuf,1,10240,inf);
if(nbytes<=0)
break;
fwrite(tmpbuf,1,nbytes,outf);
totbytes += nbytes;
}
return totbytes;
}